package com.tbit.uqbike.webmanager.controller;

import com.tbit.common.utils.SingUtil;
import com.tbit.uqbike.constant.OperaPswConstant;
import com.tbit.manager.api.dto.OperationalDataDTO;
import com.tbit.uqbike.object.pojo.vo.OperationalDataVO;
import com.tbit.uqbike.object.pojo.vo.OrderFlowKanbanVO;
import com.tbit.uqbike.object.pojo.vo.VehicleOperationVO;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.AccountDayStatService;
import com.tbit.uqbike.webmanager.util.StringUtils;
import com.tbit.utils.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 区域数据预统计
 *
 * @Author:BUGTian
 * @DATE: 2022/11/1
 */
@RestController
@RequestMapping("/accountDayStat")
public class AccountDayStatController {

    @Autowired
    private AccountDayStatService accountDayStatService;


    /**
     * 运营大屏-运营数据
     *
     * @param operationalDataDTO
     * @return
     */
    @GetMapping("/operationalData")
    public Result<Map<String, Object>> operationalData(OperationalDataDTO operationalDataDTO) {
        Map<String, Object> map = accountDayStatService.operationalData(operationalDataDTO);
        return Result.success(map);
    }

    /**
     * 运营大屏-运营数据（5.0 新）
     * @param operationalDataDTO operationalDataDTO
     * @return OperationalDataVO
     */
    @GetMapping("/operationalDataNew")
    public Result<OperationalDataVO> operationalDataNew(OperationalDataDTO operationalDataDTO) {
        return accountDayStatService.operationalDataNew(operationalDataDTO);
    }

    /**
     * 运营大屏-运营数据（运维端调用）
     *
     * @param operationalDataDTO
     * @param sign               签名
     * @param time               时间戳
     * @return
     */
    @GetMapping("/operationalDataToMain")
    public Result<Map<String, Object>> operationalDataToMain(OperationalDataDTO operationalDataDTO, String sign, Long time) {
        if (StringUtils.isEmpty(sign) || time == null) {
            return Result.error("校验参数有误");
        }
        if ((System.currentTimeMillis() - time) > 1000 * 60 * 5) {
            return Result.error("签名已过期");
        }
        if (!sign.equals(SingUtil.createSing(OperaPswConstant.ORDER_FINISH_MANUAL + time))) {
            return Result.error("签名有误");
        }
        Map<String, Object> map = accountDayStatService.operationalData(operationalDataDTO);
        return Result.success(map);
    }

    /**
     * 运营大屏-运营数据-车辆运营看板
     *
     * @param operationalDataDTO
     * @return
     */
    @GetMapping("/queryVehicleOperationVO")
    public Result<VehicleOperationVO> queryVehicleOperationVO(OperationalDataDTO operationalDataDTO) {
        Assert.notNulls("缺少必要参数", operationalDataDTO.getStartTime(), operationalDataDTO.getEndTime(), operationalDataDTO.getAccountIds(), operationalDataDTO.getBrandId());
        VehicleOperationVO vehicleOperationVO = accountDayStatService.queryVehicleOperationVO(operationalDataDTO);
        return Result.success(vehicleOperationVO);
    }

    /**
     * 运营大屏-运营数据-订单流水看板
     *
     * @param operationalDataDTO
     * @return
     */
    @GetMapping("/orderFlowKanban")
    public Result<OrderFlowKanbanVO> orderFlowKanban(OperationalDataDTO operationalDataDTO) {
        Assert.notNulls("缺少必要参数", operationalDataDTO.getStartTime(), operationalDataDTO.getEndTime(), operationalDataDTO.getAccountIds(), operationalDataDTO.getBrandId());
        OrderFlowKanbanVO orderFlowKanbanVO = accountDayStatService.orderFlowKanban(operationalDataDTO);
        return Result.success(orderFlowKanbanVO);
    }


}
